using System;

using GURUCORE.Framework.Core;
using GURUCORE.Framework.Core.Proxy;
using GURUCORE.Framework.Core.Data;
using GURUCORE.Framework.DataAccess.Provider;

using GURUCORE.Framework.Business.Security;

namespace GURUCORE.Framework.Business
{
	/// <summary>
	/// AbstractBusinessService is a class for other service derive from
	/// </summary>
	public abstract class BusinessService
	{
		public BusinessService()
		{
		}

		#region Utils

		[NonDelegated]
		protected virtual int CalculatePageCount(int p_nRecordCount, int p_nRecordPerPage)
		{
			if (p_nRecordCount == 0)
			{
				return 0;
			}
			else
			{
				return (p_nRecordCount - 1) / p_nRecordPerPage + 1;
			}
		}

		[NonDelegated]
		protected DTOCollection<T> GetLegalData<T>(DTOCollection<T> p_arrData, string p_sPermission, string p_sKeyColumn) where T: DTOBase
		{
			GURUCORE.Framework.Core.GSS.GURUID guruid = GApplication.GetInstance().GetSecurityContext(null, string.Empty);
            int nUserID = guruid.UserID;

			PermissionChecker oPermChecker = new PermissionChecker();
			return oPermChecker.CheckPermission<T>(p_arrData, nUserID, p_sPermission, p_sKeyColumn);
		}

		#endregion Utils
	}
}
